<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>insertAt</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body,html {
            height: 100%;
            background-color: rgba(0,0,0,.85);
            color:#fff;
        }
        code {
            font-size: 18px;
            color: #e90707;
            background: #babdbd;
            padding:6px 16px;
            white-space: pre-wrap;
            display: inline-block;
            text-indent: 0;
            tab-size: 4;
            margin: 14px 0;
            border-radius: 5px;
        }
        .content {
            padding: 16px;
        }
    </style>
</head>

<body>
    <div id="content" class="content"></div>
    <script>
        const insertAt = (arr, i, ...v) => {
            if (!Array.isArray(arr)) {
                return console.error('First argument should be an array!');
            }
            if (typeof i !== 'number' || (i | 0) !== i) {
                return console.error('Second argument should be an inter index!');
            }
            arr.splice(i + 1, 0, ...v);
            return arr;
        }
        const content = document.getElementById('content');
        let myArray = [1, 2, 3, 4];
        let otherArray = [2, 10];
        content.innerHTML = `
<code>let myArray = [1, 2, 3, 4];
insertAt(myArray, 2, 5);
let otherArray = [2, 10];
insertAt(otherArray, 0, 4, 6, 8);           
</code>
<p>执行结果如下:</p>
<code>${JSON.stringify(insertAt(myArray, 2, 5))}
${JSON.stringify(insertAt(otherArray, 0, 4, 6, 8))}       
</code>
        `;
    </script>
</body>

</html>